<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <meta name="geometry" content="facet">
  <link rel="stylesheet" href="./assets/common.css">
  <title>Facets List Plot</title>
</head>

<body>
  <div id="canvas"></div>
  <script src="./assets/jquery-3.2.1.min.js"></script>
  <script src="../build/g2.js"></script>
  <script>
    $.getJSON('./data/github-commit.json', function(data) {
      const chart = new G2.Chart({
        container: 'canvas',
        forceFit: true,
        height: window.innerHeight
      });
      /* const { DataView } = DataSet;
      const dv = new DataView().source(data);
      dv.transform({
        type: 'map',
        callback: obj => {
          obj.month = obj.month + '';
          return obj;
        }
      });
*/
      chart.source(data, {
        month: {
          type: 'cat'
          // values: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", 'December']
        },
        day: {
          type: 'cat',
          values: [ '0', '1', '2', '3', '4', '5', '6' ]

        },
        week: {
          type: 'cat',
          values: [ '0', '1', '2', '3', '4', '5' ]
        },
        commits: {
          sync: true
        }
      });

      // chart.axis(false);
      // chart.legend('涨跌幅', {
      //   offset: [ 0, 0 ]
      // });
      chart.tooltip({
        showTitle: false
      });
      chart.coord().reflect('y');
      chart.facet('list', {
        cols: 7,
        fields: [ 'month' ],
        eachView: view => {
          view.polygon().position('week*day')
            .color('commits', '#F51D27-#FA541C-#FFBE15-#FFF2D1-#E3F6FF-#85C6FF-#0086FA-#0A61D7')
            .style({
              lineWidth: 1,
              stroke: '#fff'
            })
            .tooltip('date*commits', (date, commits) => {
              return {
                name: date,
                value: commits
              };
            });
        }
      });

      chart.render();
    });
  </script>
</body>
</html>